#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define BUF_LEN 20

int main()
{
    int i, fd;
    ssize_t count;
    char read_buf[BUF_LEN+1], write_buf[BUF_LEN+1];

    memset(read_buf, 0, sizeof(read_buf));
    memset(write_buf, 0, sizeof(read_buf));

    for (i = 0; i < BUF_LEN; i++) {
        write_buf[i] = '0' + i;
    }

    fd = open("/dev/scull0", O_WRONLY);
    if (fd < 0) {
        perror("open failed");
        exit(1);
    }
    count = write(fd, write_buf, BUF_LEN);
    if (count < 0) {
        perror("write failed");
        exit(1);
    }
    printf("write %d bytes\n", count);

    close(fd);
#if 1
    fd = open("/dev/scull0", O_RDONLY);
    if (fd < 0) {
        perror("open failed");
        exit(1);
    }
    count = read(fd, read_buf, BUF_LEN);

    if (count < 0) {
        perror("read failed");
        exit(1);
    }

    printf("read %d bytes, content: %s\n", count, read_buf);
    close(fd);
#endif
    exit(0);
}

